package cn.loan.controller;

import cn.loan.config.key.RequestKey;
import cn.loan.config.key.SessionKey;
import cn.loan.entity.ByStages;
import cn.loan.entity.User;
import cn.loan.service.ByStagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author: 毛苏宇
 * @Description: You can do it!
 * @Date: Create in 23:46 2019/4/5
 */
@Controller
@RequestMapping("/order")
public class LoanOrderController {
    @Autowired
    private ByStagesService byStagesService;

    /**
     * 借款成功后
     *
     * @param session
     * @param request
     * @return
     */
    @RequestMapping("/loanOrder")
    public String order(HttpSession session, HttpServletRequest request) throws Exception {
        User user = (User) session.getAttribute(SessionKey.SESSION_USER);
        int userId = user.getUser_id();
        ByStages byStages = byStagesService.getLoanRecord(userId);
        if (null != byStages) {
            request.setAttribute(RequestKey.REQUEST_LOAN_ORDER, byStages);
            return "/order";
        } else {
            return "redirect:/loan/quota";
        }
    }

}
